package org.cttic.visualization.visualization.controller;

import cn.hutool.core.util.StrUtil;
import org.cttic.visualization.visualization.common.HistoryTravelRequest;
import org.cttic.visualization.visualization.util.ResponseObject;
import org.cttic.visualization.visualization.z_service.HistoryTravelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 2.5.1	行驶轨迹线历史查询
 */

@RestController
@CrossOrigin
public class HistoryTravelController {


    @Autowired
    private HistoryTravelService historyTravelService;

    @RequestMapping("api/travel/history")
    public ResponseObject findHistoryTravel(@Valid @RequestBody HistoryTravelRequest request, BindingResult binding){


        if(binding.hasErrors()){
            return ResponseObject.error(binding.getFieldError().getDefaultMessage());
        }

//        if(request.getDataType().equals("0")){
//            if(StrUtil.isEmpty(request.getDataTypeKey())){
//                return ResponseObject.error("当输入了“识别点类型”的情况下，必填");
//            }
//        }

        if(request.getQueryType().equals("2")){
            if(StrUtil.isEmpty(request.getQueryValue2())){
                return ResponseObject.error("按时间段查询时,queryValue2 必填");
            }
        }

        return historyTravelService.findHistoryTravel(request);

    }
}
